(CC-BY-NC-SA)

This document was produced on Sa Jun 04 2016 using mapview version 1.0.40


mapview provides a few convenience functions for popup creation. These popups can be used with both mapview and leaflet.


popupTable

This is the standard popup function used by mapview

library(mapview)
mapview(breweries91, zcol = "founded")


It also works with leaflet and can be controlled to only show selected columns of the attribute table

leaflet() %>% 
  addTiles() %>% 
  addCircleMarkers(data = breweries91, popup = popupTable(breweries91, zcol = c("brewery", "village", "founded")))

popupGraph

To include lattice or ggplot2 or htmlwidgets based graphs in our popups we can use ppopupGraph(). We have three options to embed grpahs in popups:

  1. type = "png" for png rendering of graphs
  2. type = "svg" for svg rendering of graphs
  3. type = "html" for html rendering of graphs (use this option to render htmlwidgets based visualisations)
  • png example:
library(sp)
library(lattice)

pt <- data.frame(x = 174.764474, y = -36.877245)

coordinates(pt) <- ~ x + y
proj4string(pt) <- "+init=epsg:4326"

p2 <- levelplot(t(volcano), col.regions = terrain.colors(100))

mapview(pt, popup = popupGraph(p2, width = 200, height = 300))


  • svg example:
data(meuse)
coordinates(meuse) <- ~ x + y
proj4string(meuse) <- CRS("+init=epsg:28992")

## create plots with points colored according to feature id
p <- xyplot(copper ~ cadmium, data = meuse@data, col = "grey")
p <- mget(rep("p", length(meuse)))

clr <- rep("grey", length(meuse))
p <- lapply(1:length(p), function(i) {
  clr[i] <- "red"
  update(p[[i]], col = clr)
})

mapview(meuse, popup = popupGraph(p, type = "svg", width = 3, height = 2.5))


  • html example:
mapview(pt, map.types = "Esri.WorldImagery", popup = popupGraph(mapview(pt)@map, type = "html"))

popupImage

Finally, it is possible to include local (on our local hard drive) or remote (from the web) images in popups

  • local images:
img <- system.file("img","Rlogo.png", package="png")
mapview(pt, popup = popupImage(img))


  • remote images:
img <- "https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/Mount_Eden.jpg/640px-Mount_Eden.jpg"

mapview(pt, map.types = "Esri.WorldImagery", popup = popupImage(img, src = "remote"))

There’s also a hidden function that enables us to include all sorts of things via Iframe (which is used internally when rendering htmlwidgets graphs).

But let the Dude show us how this can be used…

mapview(pt, popup = mapview:::popupIframe("https://www.youtube.com/embed/iApz08Bh53w?autoplay=1", width = 300, height = 225))